package org.zjx.route.model;

import com.alibaba.fastjson2.annotation.JSONType;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.zjx.route.entity.Location;
import org.zjx.route.entity.RouteType;

/**
 * 离开房间路由类
 * 表示离开房间的路径(单向)
 */

@JSONType(typeName = "RoomExitRoute")
@EqualsAndHashCode(callSuper = true)
@Data
@NoArgsConstructor
public class RoomExitRoute extends AbstractRoute {
    private int clickX;  // 需要点击的X坐标
    private int clickY;  // 需要点击的Y坐标

    /**
     * 构造函数
     *
     * @param start 起点
     * @param end   终点
     * @throws IllegalArgumentException 如果起点没有房间名
     */
    public RoomExitRoute(Location start, Location end, int clickX, int clickY) {
        super(start, end, 2, RouteType.ROOM_EXIT, false);
        if (start.getRoomName() == null) {
//            throw new IllegalArgumentException("起点必须指定房间");
        }
        if (end.getRoomName() != null) {
            throw new IllegalArgumentException("终点必须在室外");
        }
        this.clickX = clickX;
        this.clickY = clickY;
    }

    /**
     * 创建反向路由(不支持)
     *
     * @throws UnsupportedOperationException 总是抛出
     */
    @Override
    protected Route createReverseRoute() {
        throw new UnsupportedOperationException("Room exit is unidirectional");
    }

    /**
     * 获取路由描述
     *
     * @return 描述字符串
     */
    @Override
    public String getDescription() {
        return String.format("从%s离开%s，点击位置[%d,%d]，耗时%d秒",
                getStart(), getEnd().getRoomName(), clickX, clickY, getTime());
    }
}